package com.example.zhaicaoapplicationv3;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NavUtils;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

/**
 * 文本编辑区域
 * @author lxx
 * 2019.10.19
 */
public class TextEdit_Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_textedit);

        /**
         * 实现返回arrow(<-)图标:通过判断父Activity是否为空,不为空设置导航图标
         * 并显示向左箭头图标
         * @author lxx
         * 2019.10.19
         */
        if(NavUtils.getParentActivityName(TextEdit_Activity.this) != null){
            //显示向左箭头图标
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }
    /**
     * 显示菜单代码
     * 重写onCreateOptionMenu()方法来添加一个选项菜单
     * @author lxx
     * 2019.10.19
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_edit1,menu);
        return super.onCreateOptionsMenu(menu);
    }

    /**
     * 重写onOptionsItemSelected()方法，当选择保存按钮时，做出响应
     * @author lxx
     * 2019.10.19
     */
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()){
            case R.id.save_Edit_1:
                Toast.makeText(TextEdit_Activity.this,"保存成功",Toast.LENGTH_SHORT).show();
                break;
                default:break;
        }
        return super.onOptionsItemSelected(item);
    }
}
